package grape.crm.rest.customerassociatedcontactperson.mvc;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.validation.Valid;
import grape.crm.rest.customerassociatedcontactperson.form.CustomerAssociatedContactPersonCreateForm;
import grape.crm.rest.customerassociatedcontactperson.form.CustomerAssociatedContactPersonUpdateForm;
import grape.crm.rest.customerassociatedcontactperson.form.CustomerAssociatedContactPersonListPageForm;
import grape.crm.rest.customerassociatedcontactperson.vo.CustomerAssociatedContactPersonVo;
import grape.crm.rest.customerassociatedcontactperson.mapper.CustomerAssociatedContactPersonWebMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import grape.common.rest.mvc.BaseController;
import grape.crm.service.customerassociatedcontactperson.po.CustomerAssociatedContactPerson;
import grape.crm.service.customerassociatedcontactperson.api.ICustomerAssociatedContactPersonService;
import java.util.List;
/**
 * <p>
 * 关联联系人 前端控制器
 * </p>
 *
 * @author yangwei
 * @since 2020-09-24
 */
@RestController
@RequestMapping("/crm/customerassociatedcontactperson")
@Api(tags = "关联联系人相关接口")
public class CustomerAssociatedContactPersonController extends BaseController<CustomerAssociatedContactPersonVo, CustomerAssociatedContactPerson> {

    @Autowired
    private CustomerAssociatedContactPersonWebMapper currentWebMapper;
    @Autowired
    private ICustomerAssociatedContactPersonService currentService;



     @ApiOperation("添加关联联系人")
     @PreAuthorize("hasAuthority('customerassociatedcontactperson:single:create')")
     @PostMapping
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerAssociatedContactPersonVo create(@RequestBody @Valid CustomerAssociatedContactPersonCreateForm cf) {
         CustomerAssociatedContactPerson po = currentWebMapper.formToPo(cf);
         return super.create(po);
     }

     @ApiOperation("根据ID查询关联联系人")
     @PreAuthorize("hasAuthority('customerassociatedcontactperson:single:queryById')")
     @GetMapping("/{id}")
     @ResponseStatus(HttpStatus.OK)
     public CustomerAssociatedContactPersonVo queryById(@PathVariable String id) {
         return super.queryById(id);
     }

     @ApiOperation("删除关联联系人")
     @PreAuthorize("hasAuthority('customerassociatedcontactperson:single:deleteById')")
     @DeleteMapping("/{id}")
     @ResponseStatus(HttpStatus.NO_CONTENT)
     public boolean deleteById(@PathVariable String id) {
         return super.deleteById(id);
     }

     @ApiOperation("更新关联联系人")
     @PreAuthorize("hasAuthority('customerassociatedcontactperson:single:updateById')")
     @PutMapping("/{id}")
     @ResponseStatus(HttpStatus.CREATED)
     public CustomerAssociatedContactPersonVo update(@PathVariable String id,@RequestBody @Valid CustomerAssociatedContactPersonUpdateForm uf) {
         CustomerAssociatedContactPerson po = currentWebMapper.formToPo(uf);
         po.setId(id);
         return super.update(po);
     }

    @ApiOperation("分页查询关联联系人")
    @PreAuthorize("hasAuthority('customerassociatedcontactperson:single:listPage')")
    @GetMapping("/listPage")
    @ResponseStatus(HttpStatus.OK)
    public IPage<CustomerAssociatedContactPersonVo> listPage(CustomerAssociatedContactPersonListPageForm listPageForm) {
         CustomerAssociatedContactPerson po = currentWebMapper.formToPo(listPageForm);
         return super.listPage(po,listPageForm);
     }

}
